package com.tkx.dxb.service.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
 * @author : victor
 * @since : 2020/10/29
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    /**
     * 网页API配置
     */
    @Bean
    public Docket webApiConfig(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
        return docket;
    }

    @Bean
    public Docket adminApiConfig(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("admin")
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
        return docket;
    }

    /**
     * 组装参数 apiInfo()
     */
    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("网站API文档")
                .description("懂小白在线教育平台网站API接口定义文档")
                .version("1.0")
                .contact(new Contact("victor","https://space.bilibili.com/142226262","1013150998@qq.com"))
                .build();
    }

    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("网站API文档")
                .description("懂小白在线教育平台后台管理系统API接口定义文档")
                .version("1.0")
                .contact(new Contact("victor","https://space.bilibili.com/142226262","1013150998@qq.com"))
                .build();
    }

}
